package cn.shadow.client;


import cn.shadow.message.WorkerFactory;
import cn.shadow.module.chess.message.chnChess.frame.ChnChessGame;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

import java.io.Closeable;


@Service
public class ConnectionClient implements Closeable, ApplicationListener<ContextRefreshedEvent> {
    private final NettyClient nettyClient;

    public ConnectionClient(WorkerFactory factory) {
        this.nettyClient = new NettyClient("localhost", 8080, factory);
    }

    public void start() {
        nettyClient.config();
        nettyClient.start();
    }



    @Override
    public void close() {
        nettyClient.close();
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        start();

    }

    @Autowired
    ChnChessGame chnChessGame;
}


